# coding:utf-8
import os


class PicScanner:
    _path = None
    extentions = ['.jpg', '.png']  # 允许的拓展名

    def __init__(self, path):
        if len(path) > 0:
            self._path = path
            pass
        else:
            print 'path cannot be empty'

    def run(self, comparator):
        if self._path is None:
            return -1

        if comparator is None:
            print 'need a comparator'
            return -1

        iterator = os.walk(self._path)
        for dirpath, dirnames, filenames in iterator:
            for filename in filenames:
                ext = os.path.splitext(filename)[-1]
                if (ext is not None) and (ext in self.extentions):  # 包含给定的拓展名
                    filepath =  os.path.join(dirpath, filename)
                    # print 'filepath = %s' % filepath
                    self._bingo(filepath, comparator)
                    comparator.bingo(filepath)

        return comparator.report()

    def _bingo(self, filepath, comparator):
        # print 'filepath = %s' % filepath
        pass